package com.dkm.intelligenthelmet.utils.jwt.intertfaceceptor;


import com.dkm.intelligenthelmet.utils.jwt.intertfaceceptor.domain.CustomException;
import com.dkm.intelligenthelmet.utils.jwt.intertfaceceptor.domain.Code;
import com.dkm.intelligenthelmet.utils.jwt.intertfaceceptor.domain.CustomException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import javax.servlet.http.HttpServletResponse;

/**
 * @PROJECT_NAME: orproject
 * @DESCRIPTION:
 * @USER: 周佳佳
 * @DATE: 2020/7/24 9:27
 */
@RestControllerAdvice
public class GlobalExceptionAdvice extends ResponseEntityExceptionHandler {


    /**
     * 自定义返回异常
     * @param c
     * @return
     */
    @ExceptionHandler(CustomException.class)
    public CustomException handlerUserNotExistException(final CustomException c){
        return c;
    }

    /**
     * 其他异常,默认返回
     * @param e
     * @param response
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public CustomException customException (final CustomException e, HttpServletResponse response) {
        response.setStatus(Code.UNKNOWN_ERROR.getHttpStatus());
        e.printStackTrace();
        return new CustomException(Code.UNKNOWN_ERROR);
    }
}
